package client;

import common.Game;
import common.Player;
import common.PlayerGUIControl;
import common.PlayerGameBoard;


public class ClientUpdate {
	private ClientController controller;

	//
	public ClientUpdate(final ClientController g) {
		this.controller = g;
		
	}

	public void update(final Game sg) {
		
		final Player player = sg.getPlayer(sg.getCurrentPlayer());
		final PlayerGameBoard gameBoard = player.getGameBoard();
		final PlayerGUIControl guicontrol = player.getGUIControl();

		// Draw the correct border for available tiles and the player position
		this.controller.getMapButtonHandler().setTileStatus(gameBoard.getStateList());
		
		// Draw all the players' positions		
		this.controller.getMapButtonHandler().showAllPlayers(sg.getPlayerPositions());
		
		// Move panel update
		this.controller.getGUI().changeMovePanelPlayerName(player.getName());
		this.controller.getGUI().changeMovePanelPlayerImage(player.getImageIcon());
		this.controller.getGUI().changeMovePanelDiceImage(guicontrol.getDiceNumberRolled());
		if (guicontrol.getDiceNumberRolled() != 0) {
			this.controller.getGUI().changeMovePanelDiceLabel("Rolled: " + guicontrol.getDiceNumberRolled());
		} else {
			this.controller.getGUI().changeMovePanelDiceLabel("Rolled: ");
		}
		this.controller.getGUIButtonHandler().setDiceButtonState(guicontrol.getButtonState());
		// End move panel update

		

		
		// Drawn Adventure card update
		this.controller.getGUI().changeDrawnAdventureCardNameLabel(player.getName()
				+ ", you now stand on "
				+ player.getGameBoard().getCurrentTile().getTitle() + ".");
		this.controller.getGUI().changeDrawnAdventureCardTileDescription(player.getGameBoard()
				.getCurrentTile().getInfo());
		this.controller.getGUI().changeDrawnAdventureCardTileImage(player.getGameBoard()
				.getCurrentTile().getImage(300, 200));
		
		// Draws the list of currently drawn adventure cards
		if (gameBoard.getCurrentTile().getCardsOnThisTile() != null) {
			this.controller.getGUI().changeDrawnAdventureCardCardList(gameBoard.getCurrentTile().getCardsOnThisTile());
			if (gameBoard.getCurrentTile().getCurrentCardOnThisTile() != null) {
				this.controller.getGUI().changeDrawnAdventureCardCurrentCard(gameBoard.getCurrentTile().getCurrentCardOnThisTile());
			}
		}
		
		// Sets the buttons
		if ((gameBoard.getCurrentTile().needToDrawCards()) && (!player.getHasDrawnCardThisTurn())) { 
			this.controller.getGUI().setDrawAdventureCardEnabled(true);
			this.controller.getGUI().setDrawAdventureCardContinueEnabled(false);
		} else {
			this.controller.getGUI().setDrawAdventureCardEnabled(false);
			this.controller.getGUI().setDrawAdventureCardContinueEnabled(true);
		}
		
		
		// At last, repaint the GUI
		this.controller.getGUI().repaint();
		
		
		/*
		 * // Fight view update
		 * gui.changeFightPlayerImage(player.getFightImage());
		 * gui.changeFightEnemyImage(sg.getEnemyImage());
		 * gui.changeFightPlayerCombatValue(player.getCombatValue());
		 * gui.changeFightEnemyCombatValue(sg.getEnemyCombatValue());
		 * gui.changeFightEnemyRoll(sg.getEnemyCombatRoll());
		 * gui.changeFightPlayerRoll(sg.getPlayerCombatRoll());
		 * gui.changeFightOutcomeText(sg.getFightOutcomeText());
		 * gui.getFightRollButton().setEnabled(sg.getFightRollState());
		 * gui.getFightEndButton().setEnabled(sg.getFightEndState()); // End
		 * fight panel update
		 */


		/*
		 * // Special Abilities panel update //TODO change the list //
		 * gui.getSpecialAbilitiesList.set??? // End Special Abilites panel
		 * update
		 * 
		 * // Items and followers panel update ///TODO change the list
		 * //gui.getItemsList().set??? // End Items and followers panel update
		 * 
		 * // Spells panel update //TODO changethe list
		 * //gui.getSpellsList.set??? // End Spells Panel update
		 */

		/*
		 * // Game panel update
		 * gui.changeGamePanelConnectedLabel("Connected to server " +
		 * sg.getServerIP()); // End game panel update
		 */
	}
}
